#!/bin/bash

if [ $# -ne 1 ] && [ $# -ne 2 ]; then
	echo "Simple packaging file for the Windows port.  Only really useful when"
	echo "cross-compiling, or using Cygwin.  Originally by Robert Ruehlmann."
	echo ""
	echo "Use in the root directory of the game, like so:"
	echo "   scripts/pkg_win <name of of release, e.g. angband-4.0.1> [<output filename>]"
	echo ""

	exit 1
fi

DIR=$1
if [ $# -eq 1 ]; then
	OUT=$1.zip
else
	OUT=$2
fi

            
function cp_unix2dos {
  # Just in case they're already DOS_format, we strip them to UNIX first. :)
  awk '{ sub("\r$", ""); sub("$", "\r"); print }' $1 > $2
}


mkdir -p $DIR
cd $DIR

mkdir lib
mkdir lib/apex
mkdir lib/bone
mkdir lib/data
mkdir lib/edit
mkdir lib/file
mkdir lib/help
mkdir lib/info
mkdir lib/pref
mkdir lib/save
mkdir lib/script
mkdir lib/user
mkdir lib/xtra
mkdir lib/xtra/font
mkdir lib/xtra/graf
mkdir lib/xtra/sound

touch lib/apex/delete.me lib/bone/delete.me lib/data/delete.me \
      lib/info/delete.me lib/user/delete.me lib/save/delete.me

cp ../*.exe .
cp ../*.dll .

# Copy the readmes and suchlike, converting to DOS line endings on the way
cp_unix2dos ../changes.txt ./changes.txt
cp_unix2dos ../thanks.txt ./thanks.txt
cp_unix2dos ../copying.txt ./copying.txt
cp_unix2dos ../readme.txt ./readme.txt
cp_unix2dos ../faq.txt ./faq.txt

cp ../lib/edit/*.txt lib/edit
cp ../lib/file/*.txt lib/file

cp ../lib/help/*.txt lib/help
cp ../lib/help/*.hlp lib/help

cp ../lib/pref/*.prf lib/pref

cp ../lib/xtra/font/*.fon lib/xtra/font

cp ../lib/xtra/graf/8x8.png lib/xtra/graf
cp ../lib/xtra/graf/8x16.png lib/xtra/graf
cp ../lib/xtra/graf/16x16.png lib/xtra/graf
cp ../lib/xtra/graf/32x32.png lib/xtra/graf

cp ../lib/xtra/sound/sound.cfg lib/xtra/sound
cp ../lib/xtra/sound/*.wav lib/xtra/sound

cd ..
zip -9 -r $OUT $DIR
rm -rf $DIR
